//
//  WKToolsDefine.h
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/5.
//  Copyright © 2018年 何文虎. All rights reserved.
//

#ifndef WKToolsDefine_h
#define WKToolsDefine_h


//-------------------打印日志-------------------------
//DEBUG  模式下打印日志,当前行
#ifdef DEBUG
#   define NSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define NSLog(...)
#endif



////DEBUG  模式下打印日志,当前行 并弹出一个警告
//#ifdef DEBUG
//#   define ULog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
//#else
//#   define ULog(...)
//#endif


//---------------------打印日志--------------------------



//----------------------系统----------------------------

//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

//获取当前语言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//判断是否 Retina屏、设备是否%fhone 5、是否是iPad
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define IS_PAD (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad)

//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif

#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

//检查系统版本
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
#define AppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

//----------------------系统----------------------------


//----------------------内存----------------------------

//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif

#pragma mark - common functions
#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }

//释放一个对象
#define SAFE_DELETE(P) if(P) { [P release], P = nil; }

#define SAFE_RELEASE(x) [x release];x=nil



//----------------------内存----------------------------


//----------------------图片----------------------------

//读取本地图片
#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

//定义UIImage对象
#define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]

//定义UIImage对象
#define ImageNamed(_pointer) [UIImage imageNamed:_pointer]

//建议使用前两种宏定义,性能高于后者
//----------------------图片----------------------------

// 是否存在Block
#define Block_AbleE(block) if (block) { \
block();\
}
#define Block_Able(block, ID) if (block) { \
block(ID);\
}
#define Block_Able2(block, ID, ID2) if (block) { \
block(ID, ID2);\
}
#define Block_Able3(block, ID, ID2, ID3) if (block) { \
block(ID, ID2, ID3);\
}


//G－C－D
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//NSUserDefaults 实例化
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]


//由角度获取弧度 有弧度获取角度
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)
#define VIEWCORNERRADIUS 5.0

// UTF8 字符串
#define UTF8Data(str) [str dataUsingEncoding:NSUTF8StringEncoding]


// 常用属性
#define ApplicationDelegate                 ((AppDelegate *)[[UIApplication sharedApplication] delegate])
#define iOS7                                ((floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)? NO:YES)
#define NS_Bundle                           [NSBundle mainBundle]

#define iOS11                                ((floor(NSFoundationVersionNumber) >= NSFoundationVersionNumber10_11)? YES:NO)

#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhoneXS_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO)

//#define  HS_iPhoneX ((iPhoneX  ||iPhoneXR || iPhoneXS_Max) ? YES : NO)
//#define  HS_iPhoneX (ScreenWidth == 375.f && ScreenHeight == 812.f ? YES : NO)

#define HS_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size)||CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size)||CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size)) : NO)



#define BLANKSTRING(str) ((str==nil||![str isKindOfClass:[NSString class]]||str.length<=0)?@"":str)
//字符串是否为空
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )


#define IntToString(x)                      [NSString stringWithFormat:@"%d",x]
#define IntegerToString(x)                      [NSString stringWithFormat:@"%ld",x]
#define StrToString(x)                      [NSString stringWithFormat:@"%@",x]
#define StrWithString(x,str)                [NSString stringWithFormat:@"%@%@",x,str]

#define UserDefaults                        [NSUserDefaults standardUserDefaults]
#define NOTIFICATION_CENTER                 [NSNotificationCenter defaultCenter]
//#define NavBarHeight                        (iOS7 ? (HS_iPhoneX ? 88.f : 64.f) : 44.f)
//#define StatusBarHeight                     (iOS7 ? (HS_iPhoneX ? 44.f : 20.f) : 0.0)

#define NavBarHeight                        (HS_iPhoneX ? 88.f : 64.f)
#define StatusBarHeight                     (HS_iPhoneX ? 44.f : 20.f)

#define TabBarHeight                        (HS_iPhoneX ? (49.f+34.f) : 49.f)
#define  HS_TabbarSafeBottomMargin         (HS_iPhoneX ? 34.f : 0.f)
#define  HS_NavSafeTopMargin               (HS_iPhoneX ? 44.f : 0.f)
#define ScreenBounds                        [UIScreen mainScreen].bounds
#define ScreenWidth                         [[UIScreen mainScreen] bounds].size.width
#define ScreenHeight                        [[UIScreen mainScreen] bounds].size.height
#define ScreenScale                          (ScreenWidth / 320.f)
#define ViewWidth(v)                        v.frame.size.width
#define ViewHeight(v)                       v.frame.size.height
#define ViewX(v)                            v.frame.origin.x
#define ViewY(v)                            v.frame.origin.y
//得到视图的right bottom的X,Y坐标点
#define View_BX(v) (v.frame.origin.x + v.frame.size.width)
#define VIEW_BY(v) (v.frame.origin.y + v.frame.size.height )

#define IPADAIR_SCALE_WIDTH(size) ScreenWidth==768.0?size:ScreenWidth*size/768.0

#define IPADAIR_SCALE_HEIGHT(size) ScreenHeight==1024.0?size:ScreenHeight*size/1024.0

#define CGMAK(A,B,C,D) (A/2,B/2,C/2,D/2)

//视图的比例
#define SCRWIDTHBL(value) (value/375.0F)*ScreenWidth
#define SCRHEIGHTBL(value) (value/667.0F)*ScreenHeight

//func CGFloatAutoFit(_ float:CGFloat)->CGFloat {
//    let min = UIScreen.main.bounds.height < UIScreen.main.bounds.width ? UIScreen.main.bounds.height :UIScreen.main.bounds.width
//    return min / 375 * float
#define FLoatChange(size) ScreenWidth >= 375 ? size : (size * (ScreenWidth/375.0))


//#define SCRWIDTHBL(value)  (HS_iPhoneX ? (value) :(value/375.0F)*ScreenWidth)
//#define SCRHEIGHTBL(value) (HS_iPhoneX ? (value) : (value/667.0F)*ScreenHeight)

//设置需要粘贴的文字或图片
#define PasteString(string)   [[UIPasteboard generalPasteboard] setString:string];
#define PasteImage(image)     [[UIPasteboard generalPasteboard] setImage:image];


// 格式化字符串
#define FormatString(string, args...)       [NSString stringWithFormat:string, args]

//获取系统时间戳
#define getCurentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]]

//弱引用
#define WHWeakSelf(weakSelf)  __weak __typeof(&*self)weakSelf = self




#endif /* WKToolsDefine_h */
